package com.d4peng.test.jna;

import com.sun.jna.Library;
import com.sun.jna.Pointer;
import com.sun.jna.Structure;
import com.sun.jna.Union;

/**
 * Jna复杂实现:VMware的复杂实现
 *
 * @author d4peng
 * @date 2021-11-26
 */
public class JnaDemo6 {
    public static interface VixDiskLibCredType {
        public static int VIXDISKLIB_CRED_UID = 1;
        public static int VIXDISKLIB_CRED_SESSIONID = 2;
        public static int VIXDISKLIB_CRED_TICKETID = 3;
        public static int VIXDISKLIB_CRED_SSPI = 4;
        public static int VIXDISKLIB_CRED_UNKNOWN = 256;
    }

    public static interface VixDiskLibSpecType {
        public static int VIXDISKLIB_SPEC_VMX = 0;
        public static int VIXDISKLIB_SPEC_VSTORAGE_OBJECT = 1;
        public static int VIXDISKLIB_SPEC_UNKNOWN = 256;
    }


    public interface VMDK extends Library {
        int VixDiskLib_ConnectEx(VixDiskLibConnectParams.ByReference connectParams, int readOnly,
                                 String snapshotRef,
                                 String transportModes,
                                 Object connection);

        int VixDiskLib_InitEx(int majorVersion,
                              int minorVersion,
                              Pointer pointerLog,
                              Pointer pointerWarn,
                              Pointer pointerPanic,
                              String libDir,
                              String configFile);

        public static class VixDiskLibConnectParams extends Structure {
            public String vmxSpec;
            public String serverName;
            public String thumbPrint;
            public Long privateUse;

            public int credType; // 枚举的数值
            public VixDiskLibCreds creds;

            public int port;
            public int nfcHostPort;

            public String vimApiVer;    // not used
            public String reserved;   // internal use only

            public spec spec;
            public int specType;

            public static class ByValue extends VixDiskLibConnectParams implements Structure.ByValue {
            }

            ;

            public static class ByReference extends VixDiskLibConnectParams implements Structure.ByReference {
            }

            ;
        }


        public static class VixDiskLibCreds extends Union {
            public VixDiskLibUidPasswdCreds uid;
            public VixDiskLibSessionIdCreds sessionId;

            public static class ByValue extends VixDiskLibCreds implements Union.ByValue {
            }

            ;

            public static class ByReference extends VixDiskLibCreds implements Union.ByReference {
            }

            ;

            public static class VixDiskLibUidPasswdCreds extends Structure {
                public String userName;
                public String password;

                public static class ByReference extends VixDiskLibUidPasswdCreds implements Structure.ByReference {
                }

                public static class ByValue extends VixDiskLibUidPasswdCreds implements Structure.ByValue {
                }
            }

            public static class VixDiskLibSessionIdCreds extends Structure {
                public String cookie;
                public String userName;
                public String key;

                public static class ByReference extends VixDiskLibUidPasswdCreds implements Structure.ByReference {
                }

                public static class ByValue extends VixDiskLibUidPasswdCreds implements Structure.ByValue {
                }

            }
        }

        public static class VixDiskLibVStorageObjectSpec extends Structure {
            public String id;
            public String datastoreMoRef;
            public String ssId;

            public static class ByReference extends VixDiskLibVStorageObjectSpec implements Structure.ByReference {
            }

            public static class ByValue extends VixDiskLibVStorageObjectSpec implements Structure.ByValue {
            }
        }

        public static class spec extends Union {
            public VixDiskLibVStorageObjectSpec vStorageObjSpec;

            public static class ByReference extends spec implements Union.ByReference {
            }

            public static class ByValue extends spec implements Union.ByValue {
            }
        }

    }
}
